package com.base.system.managedBean;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.user.util.Browser;

import com.base.commons.SpringBeanHolder;
import com.base.organization.entity.CentralUnit;
import com.base.organization.entity.DepartmentalUnit;
import com.base.organization.service.ICentralUnitDAO;
import com.base.organization.service.IDepartmentalUnitDAO;
import com.base.security.SecurityConst;
import com.base.system.managedBean.baseBean.BaseCentralUnitBean;

/**
 * 
 * This managed bean is generated automatically
 */
@ManagedBean(name = "system_addCentralUnitBean", scope = ManagedBeanScope.REQUEST)
public class AddCentralUnitBean extends BaseCentralUnitBean {
	Log logger = LogFactory.getLog(AddCentralUnitBean.class);
	private ICentralUnitDAO centralUnitDAO = SpringBeanHolder
			.getBean("centralUnitDAO");
	private IDepartmentalUnitDAO departmentalUnitDAO = SpringBeanHolder
			.getBean("departmentalUnitDAO");

	protected void initSpecialProperty() {
	}

	@Action(id = "saveCentralUnit")
	public void saveCentralUnit() {
		centralUnit = new CentralUnit();
		this.setCentralUnitProperty();
		centralUnitDAO.insert(centralUnit);
		// 新建机构部门
		DepartmentalUnit departmentalUnit = new DepartmentalUnit();
		departmentalUnit.setCentralUnitId(centralUnit.getCentralUnitId());
		departmentalUnit.setEnable(true);
		departmentalUnit.setName(name);
		departmentalUnitDAO.saveOrUpdate(departmentalUnit);
		context.getExternalContext().getSessionMap().put(
				SecurityConst.CENTRALUNIT_SELECT_ROW_DATA, centralUnit);
		String script = "closeCenterLayoutTab('"
				+ SecurityConst.CENTRALUNIT_ADD_TAB + "')";
		showCentralUnit();
		Browser.execClientScript("window.top", script);
	}

	public void showCentralUnit() {
		String url = "/modules/system/showCentralUnit.faces";
		url = context.getExternalContext().getRequestContextPath() + url;
		String script = "addCenterLayoutTab('"
				+ SecurityConst.CENTRALUNIT_SHOW_TAB + "','" + "查看机构" + "', '"
				+ url + "')";
		Browser.execClientScript("window.top", script);
	}
}
